<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.staticfile.org/vue/2.6.11/vue.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/iview/3.5.4/styles/iview.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/iview/3.5.4/iview.min.js"></script>
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background-color: #F7F7F7;
        }

        .header {
            height: 56px;
            border-bottom: 1px solid #e9e9e9;
            line-height: 56px;
            background-color: #fff;
        }

        .header > h3 {
            margin-left: 20px;
        }

        .main {
            width: 380px;
            margin: 90px auto 0;
            background: #fff;
            border-radius: 4px;
            border: 1px solid #d8d8d8;
            padding: 20px;
        }

        .main .ivu-form-item-content {
            display: flex;
            justify-content: center;
        }

        .main .ivu-tabs-nav {
            width: 100%;
        }

        .main .ivu-tabs-nav .ivu-tabs-tab {
            width: 50%;
            text-align: center;
            margin: 0;
        }
    </style>
</head>
<body>
<div id="app">
    <header class="header">
        <h3>老年人心理健康评估：后台管理</h3>
    </header>
    <div class="main">
        <h2>管理员登录</h2>
        <i-form :model="login_form" style="margin-top: 50px;">
            <form-item prop="email">
                <i-input type="text" v-model="login_form.name" placeholder="名称" size="large">
                    <Icon type="ios-contact-outline" slot="prepend"/>
                </i-input>
            </form-item>
            <form-item>
                <i-input type="password" v-model="login_form.pwd" placeholder="密码" size="large">
                    <icon type="ios-lock-outline" slot="prepend"></icon>
                </i-input>
            </form-item>
            <form-item>
                <i-button type="primary" size="large" @click="login">登 录</i-button>
            </form-item>
        </i-form>
    </div>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script>
    var vm = new Vue({
        delimiters: ['[[', ']]'],
        el: '#app',
        data: {
            login_form: {
                name: "",
                pwd: ""
            }
        },
        mounted: function () {

        },
        methods: {
            {#登录#}
            login() {
                if (this.login_form.name) {
                    if (this.login_form.pwd) {
                        let param = new FormData();
                        param.append('name', this.login_form.name);
                        param.append('pwd', this.login_form.pwd);
                        axios.post('', param).then(res => {
                            console.log(res.data);
                            if (res.data.state) {
                                swal({
                                    title: '登陆成功',
                                    icon: "success",
                                    timer: 800
                                }).then(() => {
                                    Cookies.set('secret_key', res.data.secret_key);
                                    //保存密钥
                                    window.location.href = '/cms'
                                })
                            } else {
                                swal('登陆失败', res.data.msg, "error")
                            }
                        })
                    } else {
                        this.$Message['warning']({
                            background: true,
                            content: '请填写密码！'
                        });
                    }
                } else {
                    this.$Message['warning']({
                        background: true,
                        content: '请填写管理员名称！'
                    });
                }
            }
        }
    });
</script>
</html>
